//: polymorphism/PolyConstructors.java
// Constructors and polymorphism
// don't produce what you might expect.package polymorphism;
package polymorphism;
import static net.mindview.util.Print.*;

/**
 * 构造器内部动态调用问题
 */
class Glyph {
  void draw() { print("Glyph.draw()"); }
  //内部后期绑定
  Glyph() {
    print("Glyph() before draw()");
    //由于是构造子类对象是调用的，所以走了后期绑定
    //可以子类需要的参数还没初始化好，就会出现奇怪的东西
    draw();
    print("Glyph() after draw()");
  }
}	

class RoundGlyph extends Glyph {
  private int radius = 1;
  RoundGlyph(int r) {
    radius = r;
    print("RoundGlyph.RoundGlyph(), radius = " + radius);
    draw();
  }
  //重写了draw()
  void draw() {
    print("RoundGlyph.draw(), radius = " + radius);
  }
}

public class PolyConstructors {
  public static void main(String[] args) {
    new RoundGlyph(5);
//    new Glyph();
//    new RoundG2(7);
  }
} /* Output:
Glyph() before draw()
RoundGlyph.draw(), radius = 0
Glyph() after draw()
RoundGlyph.RoundGlyph(), radius = 5
*///:~
